package android.hermes;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;

import android.os.Handler;
import android.os.Message;

public class WelcomeServer extends Thread implements Runnable {

	InetAddress incoming;
	Handler h = new Handler();
	
	public void run() {
		while(true) {
			try {
				DatagramSocket ds = new DatagramSocket(7501);
				byte[] buf = new byte[1];
				buf[0] = (byte) 10101010;				
				DatagramPacket packet = new DatagramPacket(buf, buf.length);
				
				ds.receive(packet);
				
				incoming = packet.getAddress();
				
				Message msg = new Message();
				msg.obj = incoming;
				msg.what = Hermes.IP;
	
				h.sendMessage(msg);
				
			} catch (SocketException e) {
				
			} catch (IOException e) {
				
			}
		}
	}
}
